package com.all.play.myapplication.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.all.play.myapplication.Bean.NewsResaultBeanData;
import com.all.play.myapplication.R;
import com.all.play.myapplication.adapter.MyNewsAdapter;
import com.all.play.myapplication.base.BaseFragment;
import com.all.play.myapplication.utils.ResaultData;
import com.google.gson.Gson;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 聪明一只哈 on 2018/4/18.
 * Time: 2018/4/18  15:02
 */

public class NewsFragment extends BaseFragment {


    @BindView(R.id.rv_news)
    RecyclerView rvNews;
    Unbinder unbinder;

    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.fragment_news, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void initData() {
        super.initData();

        String data= ResaultData.data;
        NewsResaultBeanData beanData = new Gson().fromJson(data, NewsResaultBeanData.class);

        if (beanData!=null){
            MyNewsAdapter myNewsAdapter = new MyNewsAdapter(mContext,beanData);

            rvNews.setAdapter(myNewsAdapter);

            rvNews.setLayoutManager(new LinearLayoutManager(mContext));
        }




    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();

        unbinder.unbind();

    }

}
